package cn.cnf.service.impl;

import cn.cnf.entity.ComicDetails;
import cn.cnf.mapper.ComicDetailsMapper;
import cn.cnf.service.ComicDetailsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 服务接口实现
 *
 * @author ZhuMeiYi
 * @description
 * @since 2020-12-04 15:18:43
 */
@Slf4j
@RequiredArgsConstructor(onConstructor = @_(@Autowired))
@Service
@Transactional(rollbackFor = {RuntimeException.class, Error.class})
public class ComicDetailsServiceImpl extends ServiceImpl<ComicDetailsMapper, ComicDetails> implements ComicDetailsService {

    private final ComicDetailsMapper comicDetailsMapper;

    @Override
    public List<ComicDetails> selectDetails(String comicId, String chapterId) {

        LambdaQueryWrapper<ComicDetails> wrapper = new LambdaQueryWrapper<ComicDetails>()
                .eq(ComicDetails::getComicId, comicId)
                .eq(ComicDetails::getComicChapterId, chapterId)
                .orderByAsc(ComicDetails::getSortNum);

        return comicDetailsMapper.selectList(wrapper);

    }

    @Override
    public boolean delete(String comicId) {
        return remove(new LambdaQueryWrapper<ComicDetails>()
                .eq(ComicDetails::getComicId, comicId));
    }

    @Override
    public boolean delete(String comicId, String chapterId) {
        // 删除章节详细
        return remove(new LambdaQueryWrapper<ComicDetails>()
                .eq(ComicDetails::getComicId, comicId)
                .eq(ComicDetails::getComicChapterId, chapterId));
    }
}